<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%document}}".
 *
 * @property string $id
 * @property string $uid
 * @property string $title
 * @property string $description
 * @property string $content
 * @property string $image
 * @property string $category_id
 * @property string $view
 * @property string $comment
 * @property string $create_time
 * @property integer $status
 */
class Document extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%document}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['uid', 'category_id', 'view', 'comment'], 'integer'],
            [['title', 'content', 'category_id'], 'required'],
            [['content'], 'string'],
            [['title', 'image'], 'string', 'max' => 80],
            [['description'], 'string', 'max' => 200],

			[['view', 'create_time'], 'default', 'value' => function ($model, $attribute) {
				switch ($attribute) {
					case 'view':
						return 0;
					case 'create_time':
						return time();
				}
			}]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'uid' => '布人发id',
            'title' => '文章标题',
            'description' => '文章描述',
            'content' => '文章内容',
            'image' => '面封图片',
            'category_id' => '分类',
            'view' => '览量浏（点击数）',
            'comment' => '论评数',
            'create_time' => '创建时间',
            'status' => '态状',
        ];
    }
}
